<template>
  <div id="app">
    <div v-if="$route.meta.isShell==true">
      <router-view></router-view>
    </div>
    <div v-if="$route.meta.isShell!=true">
      <!--公共导航栏-->
      <div class="box-vertical">
        <div class="background-image navivagor-image" v-if="$route.meta.keepAlive">
          <span style="color: white;font-weight: bold;font-size: 30px;padding: 10vh;">基于QEMU嵌入式Linux系统虚拟仿真环境的构建实验</span>
        </div>
        <div class="box-standard" style="justify-content: space-around;width: 100%;">
          <div>
            <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" router>
              <el-menu-item>
                <img src="./assets/images/logo.png" style="height: 60px;">
              </el-menu-item>
              <el-menu-item index="/main">首页</el-menu-item>
              <el-menu-item index="2">项目团队</el-menu-item>
              <el-menu-item index="3">项目简介视频</el-menu-item>
              <el-menu-item index="/description">项目描述</el-menu-item>
              <el-menu-item index="5">项目技术架构</el-menu-item>
              <el-menu-item index="/login" v-if="isLogin?false:true">登陆</el-menu-item>
              <el-menu-item index="/register" v-if="isLogin?false:true">注册</el-menu-item>
              <el-submenu index="9" v-if="isLogin?true:false">
                <template slot="title" :userNickname=userNickname>
                  <i class="el-icon-user"></i>
                  {{userNickname}}
                </template>
                <el-menu-item v-if="isTeacher==false"  index="/usermanagement/userinformation">个人信息</el-menu-item>
                <!--主机界面对于学生和教师是不同的额-->
                <el-menu-item v-if="isTeacher==false" index="/usermanagement/userhostaccount">主机账号</el-menu-item>
                <el-menu-item v-if="isTeacher==false" index="/usermanagement/homework">作业信息</el-menu-item>
                <el-menu-item v-if="isTeacher==false" index="/usermanagement/edithomework">提交作业</el-menu-item>
                <el-menu-item v-if="isTeacher" index="/managermanagement/managerinformation">个人信息</el-menu-item>
                <el-menu-item v-if="isTeacher" index="/managermanagement/homeworkcollection">作业集</el-menu-item>
                <el-menu-item v-if="isTeacher" index="/managermanagement/host">主机</el-menu-item>
                <el-menu-item v-if="isTeacher" index="/managermanagement/managerhostaccount">主机账号</el-menu-item>
                <el-menu-item v-if="isTeacher" index="/managermanagement/statistic">流量统计</el-menu-item>
                <el-menu-item index="" @click="logout">退出</el-menu-item>
              </el-submenu>
            </el-menu>
          </div>
        </div>
      </div>
      <router-view></router-view>
      <div id="footer" class="box-vertical">
        <div class="footer-box box-standard">
          <div class="logo-container">
            <img src="./assets/images/logo.png" style="height: 60px;">
          </div>
          <div style="border-right: 3px solid #c1c1c1;height: 100%;"></div>
          <div class="left-align footer-text">
            <div>电话：0574-88130024 地址：浙江省宁波市xxx 邮箱：xxx@163.com</div>
            <div>快速导航: 首页 项目简介视频 实验教学团队 资质荣誉 实验案例 持续建设 联系我们</div>
            <div>版权所有 xxxxx统计 浙ICP备20003870号-2</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: 'App',
  data() {
    return {
      activeIndex: '/login'
    };
  },
  computed:{
    isLogin:function () {
      return this.$store.state.user.isLogin;
    },
    userNickname:function(){
      return this.$store.state.user.userNickname;
    },
    preRoute:function () {
      return this.$store.state.user.userIsTeacher==1?'managermanagement':'usermanagement';
    },
    isTeacher:function () {
      return this.$store.state.user.userIsTeacher==1?true:false;
}
  },
  methods:{
    logout:function () {
      let data = this.$data;
      let app = this;
      this.axios.post('/user/logout')
      .then(response => {
        let resData = response.data;
        if(resData.errCode==200){
          data.isLogin = false;
          app.$store.commit("changeLoginState");
          app.$message({
            message: "退出成功",
            type: "success"
          })
          app.$router.push({
            path: '/'
          })
        }else{
          app.$message({
            message: resData.errMsg,
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: #2c3e50;
    height: 100%;
    width: 100%;
  }
  .navivagor-image{
    /*border: 1px solid black;*/
    width: 100%;
    height: 300px;
    background-image: url("assets/images/background1.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    /*background-position: 0 50%;*/
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  a{
    text-decoration: none;
  }
  #footer{
    width: 100%;
    height: 65px;
    background-color: #7f8c8d;
    border-top: 1px solid #ecf0f1;
    color: white;
  }
  .logo-container{
    width: 340px;
    height: 65px;
    padding-right: 5px;
  }
  .footer-text{
    margin-left: 5px;
    font-size: 10px;
    line-height: 15px;
    color: white;
  }
</style>
